
	clear all

	
use "Data/Raw/endline_1_merged.dta"
	
	
* Label and rename raw variables

	la var startdate "Endline 1: Start date"
	la var enddate "Endline 1: End date"
	la var age "Endline 1: Age (raw)"
	la var citizenship "Endline 1: Citizenship (raw)"

	
	ren donate_2_1 donate_ba
	
	ren donate_2_2 donate_allsides
	
	ren donate_2_3 donate_lrc
		
	ren val_voters_therm_1 therm_inparty
	
	ren val_voters_therm_2 therm_outparty
	
	ren val_trust_inparty trust_inparty
	
	ren val_trust_outparty trust_outparty
	
	
		




*Amtalks variable cleaning	
	

	
	replace answered_amtalks = 0 if progress>=98 & progress!=. & answered_amtalks==.
	
	gen avail_amtalks = (at_avail!="I can't make either time but I'm interested in other events." & at_avail!="")
		replace avail_amtalks = 0 if progress>=98 & progress!=. & avail_amtalks==.
	
	gen attend_amtalks = 1 if at_attend=="yes"
		replace attend_amtalks = 0 if at_attend=="NA"
		replace attend_amtalks = 0 if progress>=98 & progress!=. & attend_amtalks==.
	

	
	
*Social media data 
		
	egen total_social = rowtotal(fb1_like fb1_com fb1_share fb2_share tw1_like tw1_rt tw1_com tw2_com ig1_like)
		replace total_social = . if fb1_like==. & fb1_com==. & fb1_share==. & fb2_share==. & tw1_like==. & tw1_rt==. & tw1_com==. & tw2_com==. & ig1_like==.
		
	gen any_social = (fb1_like==1 | fb1_com==1 | fb1_share==1 | fb2_share==1 | tw1_like==1 | tw1_rt==1 | tw1_com==1 | tw2_com==1 | ig1_like==1)
		replace any_social = . if fb1_like==. & fb1_com==. & fb1_share==. & fb2_share==. & tw1_like==. & tw1_rt==. & tw1_com==. & tw2_com==. & ig1_like==.
	
	gen social_missing = (any_social==.)
	

	
		
* Generate variables

	* Clean party ID
	
		gen partyID_endline1=0 if inparty=="Democrat"
			replace partyID_endline1=1 if inparty=="Republican"
		
			cap la def partyID_endline1 0 "Democrat" 1 "Republican"
			la val partyID_endline1 partyID_endline1
			la var partyID_endline1 "Endline 1: Party ID"
				
		gen partyID_endline1_alt=0 if partisanship==2
			replace partyID_endline1_alt=1 if partisanship==1
			replace partyID_endline1_alt=2 if partisanship==3
			
			replace partyID_endline1_alt=0 if partisanship_4_text==" (No party is one I'd call myself a member of, but I usually vote Democrat)"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Catholic Christian Democrat"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Democrat/Independent"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Democratic Socialist"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Green"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Green Party"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Green Zionist"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Leftist"
			replace partyID_endline1_alt=0 if partisanship_4_text=="Progressive"
			replace partyID_endline1_alt=0 if partisanship_4_text=="anti-capitalist"			
				
			replace partyID_endline1_alt=1 if partisanship_4_text=="Constitutionalist but registered Republican"
			replace partyID_endline1_alt=1 if partisanship_4_text=="Libertarian"
				
			replace partyID_endline1_alt=2 if partisanship_4_text=="Balanced"
			replace partyID_endline1_alt=2 if partisanship_4_text=="Depends on civic/social topic"
			replace partyID_endline1_alt=2 if partisanship_4_text=="Depends on the issue.   I don't box myself in"
			replace partyID_endline1_alt=2 if partisanship_4_text=="Exhausted Middle"
			replace partyID_endline1_alt=2 if partisanship_4_text=="It depends on issue"
			replace partyID_endline1_alt=2 if partisanship_4_text=="Politically homeless"
			replace partyID_endline1_alt=2 if partisanship_4_text=="The two major parties are too extreme - the independent party is ineffective."
			replace partyID_endline1_alt=2 if partisanship_4_text=="Unaffiliated"
			replace partyID_endline1_alt=2 if partisanship_4_text=="used to be a Republican"
				
			replace partyID_endline1_alt=2 if partisanship_4_text=="" & partisanship==4
				
			cap la def partyID_endline1_alt 0 "Democrat" 1 "Republican" 2 "Independent"
			la val partyID_endline1_alt partyID_endline1_alt
			la var partyID_endline1_alt "Endline 1: Party ID (with Independents)"
								
			gen partyID_endline1_D = (partyID_endline1_alt==0) if partyID_endline1_alt!=.
				la var partyID_endline1_D "Endline 1: Democrat (with Independents)"
				
			gen partyID_endline1_R = (partyID_endline1_alt==1) if partyID_endline1_alt!=.
				la var partyID_endline1_R "Endline 1: Republican (with Independents)"
				
			gen partyID_endline1_I = (partyID_endline1_alt==2) if partyID_endline1_alt!=.
				la var partyID_endline1_I "Endline 1: Independent (with Independents)"
							
			gen partyID_merged_D = (partyID_merged==0) if partyID_merged!=.
			gen partyID_merged_R = (partyID_merged==1) if partyID_merged!=.
			gen partyID_merged_I = (partyID_merged==2) if partyID_merged!=.
							
								
	* Generate inparty vs. outparty feeling thermometer
	
		gen therm_diff = therm_inparty-therm_outparty
			la var therm_diff "Endline 1: Inparty vs. outparty feeling thermometer"
	
		gen therm_inparty_alt = therm_inparty
			replace therm_inparty_alt = therm_outparty if therm_diff<0
		gen therm_outparty_alt = therm_outparty
			replace therm_outparty_alt = therm_inparty if therm_diff<0
			
		gen therm_diff_alt = therm_inparty_alt-therm_outparty_alt
			la var therm_diff_alt "Endline 1: Inparty vs. outparty feeling thermometer (negative values imputed)"
		
		gen therm_cool_inparty = 100-therm_inparty
			la var therm_cool_inparty "Endline 1: Inparty coolness"

		gen therm_cool_outparty = 100-therm_outparty
			la var therm_cool_outparty "Endline 1: Outparty coolness"
			
			
	* Generate negative partisanship dummy
		
		gen neg_partisan = (val_neg_part==4) if val_neg_part!=.
			la var neg_partisan "Endline 1: Negative partisanship"
	
	* Generate inparty vs. outparty trust
	
		gen trust_diff = trust_inparty - trust_outparty
			la var trust_diff "Endline 1: Inparty vs. outparty trust"

		gen trust_inparty_alt = trust_inparty
			replace trust_inparty_alt = trust_outparty if trust_diff<0
		gen trust_outparty_alt = trust_outparty
			replace trust_outparty_alt = trust_inparty if trust_diff<0
	
		gen trust_diff_alt = trust_inparty_alt - trust_outparty_alt
			la var trust_diff_alt "Endline 1: Inparty vs. outparty trust (negative values imputed)"

		gen distrust_inparty = 6-trust_inparty
			la var distrust_inparty "Endline 1: Inparty distrust"

		gen distrust_outparty = 6-trust_outparty
			la var distrust_outparty "Endline 1: Outparty distrust"
	
	* Generate comfort with outparty
	
		gen comfort_outparty_friends =  val_close_friends
		gen comfort_outparty_neighbors = val_neighbor
		gen comfort_outparty_marriage = val_marriage
	
	* Generate threat perceptions 
	
			/* RB 5/5/22: Note that this is not a dummy as specified in the PAP */
	
		gen threat_outparty_cit = val_prop_citizens 
		gen threat_outparty_pol = val_prop_pols 
	
	* Generate affective polarization index
	
		alpha therm_diff neg_partisan trust_diff comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_temp)
			egen aff_pol_idx = std(aff_pol_idx_temp)
				la var aff_pol_idx "Endline 1: Attitudinal affective polarization index"
					drop aff_pol_idx_temp
				
		alpha therm_cool_outparty neg_partisan distrust_outparty comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_out_temp)
			egen aff_pol_idx_out = std(aff_pol_idx_out_temp)
				la var aff_pol_idx_out "Endline 1: Attitudinal affective polarization index (outparty only)"
					drop aff_pol_idx_out_temp
*Alpha in text, p. 15
		alpha therm_diff trust_diff comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_noneg_temp)
			egen aff_pol_idx_noneg = std(aff_pol_idx_noneg_temp)
				la var aff_pol_idx_noneg "Endline 1: Attitudinal affective polarization index (no negative partisanship)"
					drop aff_pol_idx_noneg_temp
*Alpha in text, p. 15								
		alpha therm_cool_outparty distrust_outparty comfort_outparty_friends comfort_outparty_neighbors comfort_outparty_marriage threat_outparty_cit threat_outparty_pol, std item detail gen(aff_pol_idx_noneg_out_temp)
			egen aff_pol_idx_noneg_out = std(aff_pol_idx_noneg_out_temp)
				la var aff_pol_idx_noneg_out "Endline 1: Attitudinal affective polarization index (outparty only, no negative partisanship)"
					drop aff_pol_idx_noneg_out_temp
			
	* Generate issue importance index
	
		alpha immigration_imp health_imp abortion_imp gun_imp, std item detail gen(issue_imp_idx_temp)
			egen issue_imp_idx = std(issue_imp_idx_temp)
				la var issue_imp_idx "Endline 1: Issue importance index"
					drop issue_imp_idx_temp
			
			
			
	* Clean perspective taking index
	
		gen pers_see = 1 if persp_1 == 7
			replace pers_see=2 if persp_1 == 6
			replace pers_see=3 if persp_1 == 5
			replace pers_see=4 if persp_1 == 2
			replace pers_see=5 if persp_1 == 1

		gen pers_understand = 1 if persp_2 == 1
			replace pers_understand=2 if persp_2 == 2
			replace pers_understand=3 if persp_2 == 5
			replace pers_understand=4 if persp_2 == 6
			replace pers_understand=5 if persp_2 == 7

		alpha pers_see pers_understand, std item detail gen(perspective_idx_temp)
			egen perspective_idx = std(perspective_idx_temp)
				la var perspective_idx "Endline 1: Perspective taking"
					drop perspective_idx_temp
			
	* Clean antidemocratic attitudes
	
		/* 
		
			antidem1_rep
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose
		
			antidem2_rep
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose

			antidem3_rep
				2 = Strongly support
				1 = Somewhat support
				4 = Somewhat oppose
				5 = Strongly oppose

			antidem4_rep
				2 = Strongly support
				1 = Somewhat support
				4 = Somewhat oppose
				5 = Strongly oppose

			antidem4_rep
				2 = Strongly support
				1 = Somewhat support
				4 = Somewhat oppose
				5 = Strongly oppose

			antidem6_rep
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose

			antidem7_rep
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose

				
				
			antidem1_dem
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose
			
			antidem2_dem
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose
			
			antidem3_dem
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose

			antidem4_dem
				1 = Strongly support
				2 = Somewhat support
				5 = Somewhat oppose
				6 = Strongly oppose

			antidem6_dem
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose
			
			antidem7_dem
				1 = Strongly support
				2 = Somewhat support
				3 = Somewhat oppose
				4 = Strongly oppose
					
			*/
	
		foreach n of numlist 1 2 6 7 {
			gen antidem`n'_rep_rec = 1 if antidem`n'_rep == 4
			replace antidem`n'_rep_rec = 2 if antidem`n'_rep == 3
			replace antidem`n'_rep_rec = 3 if antidem`n'_rep == 2
			replace antidem`n'_rep_rec = 4 if antidem`n'_rep == 1
				}
		
		foreach n of numlist 1 2 3 6 7 {
			gen antidem`n'_dem_rec = 1 if antidem`n'_dem == 4
			replace antidem`n'_dem_rec = 2 if antidem`n'_dem == 3
			replace antidem`n'_dem_rec = 3 if antidem`n'_dem == 2
			replace antidem`n'_dem_rec = 4 if antidem`n'_dem == 1
				}
	
		foreach n of numlist 3 4 {
			gen antidem`n'_rep_rec = 1 if antidem`n'_rep == 5
			replace antidem`n'_rep_rec = 2 if antidem`n'_rep == 4
			replace antidem`n'_rep_rec = 3 if antidem`n'_rep == 1
			replace antidem`n'_rep_rec = 4 if antidem`n'_rep == 2
				}
		
		foreach n of numlist 4 {
			gen antidem`n'_dem_rec = 1 if antidem`n'_dem == 6
			replace antidem`n'_dem_rec = 2 if antidem`n'_dem == 5
			replace antidem`n'_dem_rec = 3 if antidem`n'_dem == 2
			replace antidem`n'_dem_rec = 4 if antidem`n'_dem == 1
				}
	
	
		foreach n of numlist 1 2 3 4 6 7 {
			gen antidem`n'=antidem`n'_dem_rec
				replace antidem`n'=antidem`n'_rep_rec if antidem`n'==.
		}
	
		alpha antidem1 antidem2 antidem3 antidem4 antidem6 antidem7, std item detail gen(antidem_idx_temp)
			egen antidem_idx = std(antidem_idx_temp)
				la var antidem_idx "Endline 1: Anti-democratic attitudes"
					drop antidem_idx_temp

		foreach x of varlist antidem1 antidem2 antidem3 antidem4 antidem6 antidem7 {
			gen `x'_dum = (`x'==3 | `x'==4) if `x'!=.
		}
		
		
		
		
	* Clean tolerance for racism and misinformation
		
		foreach n of numlist 1 2 {
			gen tol_misinfo`n'=1-mis`n'_dem
				replace tol_misinfo`n'=1-mis`n'_rep if tol_misinfo`n'==.
			gen tol_racism`n'=1-race`n'_dem
				replace tol_racism`n'=1-race`n'_rep if tol_racism`n'==.
			
			gen confront_misinfo`n' = mis`n'_dem
				replace confront_misinfo`n'=mis`n'_rep if confront_misinfo`n'==.
			gen confront_racism`n' = race`n'_dem
				replace confront_racism`n'=race`n'_rep if confront_racism`n'==.
				
			}
		
		gen tol_misinfo_dum = (tol_misinfo1==1 | tol_misinfo2==1)
			replace tol_misinfo_dum=. if tol_misinfo1==. & tol_misinfo2==.

		*gen tol_misinfo_idx = tol_misinfo1 + tol_misinfo2

		alpha tol_misinfo1 tol_misinfo2, std item detail gen(tol_misinfo_idx_temp)
			egen tol_misinfo_idx = std(tol_misinfo_idx_temp)
				drop tol_misinfo_idx_temp
		
		alpha confront_misinfo1 confront_misinfo2, std item detail gen(confront_misinfo_idx_temp)
			egen confront_misinfo_idx = std(confront_misinfo_idx_temp)
				drop confront_misinfo_idx_temp
		
		gen tol_racism_dum = (tol_racism1==1 | tol_racism2==1)
			replace tol_racism_dum=. if tol_racism1==. & tol_racism2==.
			
		*gen tol_racism_idx = tol_racism1 + tol_racism2

		alpha tol_racism1 tol_racism2, std item detail gen(tol_racism_idx_temp)
			egen tol_racism_idx = std(tol_racism_idx_temp)
				drop tol_racism_idx_temp

		alpha confront_racism1 confront_racism2, std item detail gen(confront_racism_idx_temp)
			egen confront_racism_idx = std(confront_racism_idx_temp)
				drop confront_racism_idx_temp
		
		alpha tol_racism1 tol_racism2 tol_misinfo1 tol_misinfo2, std item detail gen(tol_rac_mis_idx_temp)
			egen tol_rac_mis_idx = std(tol_rac_mis_idx_temp)
				drop tol_rac_mis_idx_temp
		
		alpha confront_racism1 confront_racism2 confront_misinfo1 confront_misinfo2, std item detail gen(confront_rac_mis_idx_temp)
			egen confront_rac_mis_idx = std(confront_rac_mis_idx_temp)
				drop confront_rac_mis_idx_temp

		
		
	* Clean preference for interacting with outparty

		gen cross_grouppref_inparty = (cross_grouppref==1) if cross_grouppref!=.
			la var cross_grouppref_inparty "Endline 1: Would prefer interacting with ingroup in future"

	
		gen cross_grouppref_outparty = (cross_grouppref==2) if cross_grouppref!=.
			la var cross_grouppref_outparty "Endline 1: Would prefer interacting with outgroup in future"
		
		gen cross_grouppref_out_mixed = (cross_grouppref!=1) if cross_grouppref!=.
			la var cross_grouppref_out_mixed "Endline 1: Would prefer interacting with mixed or outgroup in future"
		
		
	* Clean skills questions
	
		gen sbd_skills_uptake_multi = sbd_close_rep
			replace sbd_skills_uptake_multi = sbd_close_dem if sbd_skills_uptake_multi==.
				la def sbd_skills_uptake_multi 1 "Reiterate speaker's concern" 2 "Caricature speaker's point" 3 "Correct speaker" 4 "Change subject"
				la val sbd_skills_uptake_multi sbd_skills_uptake_multi
				la var sbd_skills_uptake_multi "Endline 1: SDB skills"
		
		gen dw_skills_uptake_multi = dw_close_rep
			replace dw_skills_uptake_multi = dw_close_dem if dw_skills_uptake_multi==.
			replace dw_skills_uptake_multi = dw_skills_uptake_multi-1
				la def dw_skills_uptake_multi 1 "Act superior" 2 "Correct speaker" 3 "Reiterate speaker's concern" 4 "Change subject"
				la val dw_skills_uptake_multi dw_skills_uptake_multi
				la var dw_skills_uptake_multi "Endline 1: DW skills"
		
		gen sbd_skills_uptake_rep = (sbd_close_rep==1) if sbd_close_rep!=.
		gen sbd_skills_uptake_dem = (sbd_close_dem==1) if sbd_close_dem!=.
		gen sbd_skills = sbd_skills_uptake_rep
			replace sbd_skills = sbd_skills_uptake_dem if sbd_skills==.
			la var sbd_skills "Endline 1: Understood SBD skills"

		gen dw_skills_uptake_rep = (dw_close_rep==4) if dw_close_rep!=.
		gen dw_skills_uptake_dem = (dw_close_dem==4) if dw_close_dem!=.
		gen dw_skills = dw_skills_uptake_rep
			replace dw_skills = dw_skills_uptake_dem if dw_skills==.
			la var dw_skills "Endline 1: Understood DW skills"

		gen dw_sbd_skills = (dw_skills==1 & sbd_skills==1)
			la var dw_sbd_skills "Endline 1: Understood DW and SBD skills"
			
		gen sbd_skills_ign_rep = (sbd_close_rep==4) if sbd_close_rep!=.
		gen sbd_skills_ign_dem = (sbd_close_dem==4) if sbd_close_dem!=.
		gen sbd_skills_ign = sbd_skills_ign_rep
			replace sbd_skills_ign = sbd_skills_ign_dem if sbd_skills_ign==.
			la var sbd_skills_ign "Endline 1: Suggested changing subject on SBD skills"

		gen dw_skills_ign_rep = (dw_close_rep==5) if dw_close_rep!=.
		gen dw_skills_ign_dem = (dw_close_dem==5) if dw_close_dem!=.
		gen dw_skills_ign = dw_skills_ign_rep
			replace dw_skills_ign = dw_skills_ign_dem if dw_skills_ign==.
			la var dw_skills_ign "Endline 1: Suggested changing subject on DW skills"
			
		gen skills_ign_dum = (dw_skills_ign==1 | sbd_skills_ign==1)
			replace skills_ign_dum=. if dw_skills_ign==. & sbd_skills_ign==.
			la var skills_ign_dum "Endline 1: Suggested changing subject on either skills question"

		gen skills_ign_dum_both = (dw_skills_ign==1 & sbd_skills_ign==1)
			replace skills_ign_dum_both=. if dw_skills_ign==. & sbd_skills_ign==.
			la var skills_ign_dum_both "Endline 1: Suggested changing subject on both skills questions"
			
		gen skills_ign_idx_add = dw_skills_ign + sbd_skills_ign
			egen skills_ign_idx_add_std = std(skills_ign_idx_add)
			la var skills_ign_idx_add "Endline 1: Suggested changing subject on skills questions index (additive)"
			la var skills_ign_idx_add_std "Endline 1: Suggested changing subject on skills questions index (additive, standardized)"
			
		alpha dw_skills_ign sbd_skills_ign, std item detail gen(skills_ign_idx_temp)
			egen skills_ign_idx = std(skills_ign_idx_temp)
				la var skills_ign_idx "Endline 1: Suggested changing subject on skills questions index"
					drop skills_ign_idx_temp
			
			
			
	* Clean donations
		
		foreach x of varlist donate_ba donate_allsides donate_lrc {
			replace `x'=0 if donate_intro==5
			replace `x'=0 if donate_intro==4 & `x'==.
			replace `x'=0 if progress>90 & progress!=. & `x'==.
			gen `x'_any = `x'>0 & `x'!=.
		}
		
			la var donate_ba "Endline 1: Donations to Braver Angels"
		
		gen donate_total = donate_ba + donate_allsides + donate_lrc
			la var donate_total "Endline 1: All donations"
		
		gen donate_total_any = (donate_total>0) if donate_total!=.
			la var donate_total "Endline 1: Any donations"
		
		gen donate_non_ba = donate_allsides + donate_lrc
			la var donate_non_ba "Endline 1: Donations to AllSides and Living Room Conversations"
		
		gen donate_non_ba_any = (donate_non_ba>0) if donate_non_ba!=.
			la var donate_non_ba_any "Endline 1: Any donations to AllSides and Living Room Conversations"
	
	
	* Clean frequency of contact with outparty
	
		gen cross_interact_temp = cross_interact-10
			egen cross_interact_freq = std(cross_interact_temp)
	
	* Clean quality of contact with outparty
	
		gen cross_interact_stress = (cross_infostress==2) if cross_infostress!=.
	
	* Clean interest in America Talks
	
		split startdate, p("/")
			destring startdate1, replace
			destring startdate2, replace
			ren startdate1 endline_start_month
			ren startdate2 endline_start_day
	
		split startdate3, p(" ")
		split startdate32, p(":")
			destring startdate321, replace
			ren startdate321 endline_start_hour
		
		gen post_amtalks = (endline_start_month==5) if startdate!=""
			replace post_amtalks = 1 if endline_start_month==4 & endline_start_day>23 & startdate!=""
			replace post_amtalks = 1 if endline_start_month==4 & endline_start_day==23 & endline_start_hour>13 & startdate!=""
	
		gen clicked_amtalks = clickedamtalks
			replace clicked_amtalks = . if post_amtalks==1
			replace clicked_amtalks = . if progress<=90 & progress!=.
	
		
	* Clean time between survey dissemination and survey response
			
		gen days_since_endline1 = endline_start_day-11 if endline_start_month==4
			replace days_since_endline1 = endline_start_day+19 if endline_start_month==5

	
	* Clean time between assigned workshop and survey response
	
		gen days_bw_workshop_endline1 = endline_start_day+26 if endline_start_month==4 & treat_march5==1
			replace days_bw_workshop_endline1 = endline_start_day+56 if endline_start_month==5 & treat_march5==1
		
			replace days_bw_workshop_endline1 = endline_start_day+19 if endline_start_month==4 & treat_march12==1
			replace days_bw_workshop_endline1 = endline_start_day+49 if endline_start_month==5 & treat_march12==1

			replace days_bw_workshop_endline1 = endline_start_day+12 if endline_start_month==4 & treat_march19==1
			replace days_bw_workshop_endline1 = endline_start_day+42 if endline_start_month==5 & treat_march19==1

			replace days_bw_workshop_endline1 = endline_start_day+5 if endline_start_month==4 & treat_march26==1
			replace days_bw_workshop_endline1 = endline_start_day+35 if endline_start_month==5 & treat_march26==1
			
			replace days_bw_workshop_endline1 = . if aff_pol_idx_noneg==.
			
			
	* Clean demographics
	
		gen gender_endline1 = 0 if demo_gender==1
			replace gender_endline1 = 1 if demo_gender==4
			replace gender_endline1 = 2 if demo_gender==2 | demo_gender==5 | demo_gender==7
			
			la def gender_endline1 0 "Man" 1 "Woman" 2 "Other"
			la val gender_endline1 gender_endline1
			
		gen gender_endline1_m = (gender_endline1==0) if gender_endline1!=.
			la var gender_endline1_m "Endline 1: Male"
			
		gen gender_endline1_f = (gender_endline1==1) if gender_endline1!=.
			la var gender_endline1_f "Endline 1: Female"
			
		gen gender_endline1_oth = (gender_endline1==2) if gender_endline1!=.
			la var gender_endline1_f "Endline 1: Non-binary"
			
		gen ethnicity_white = (demo_ethnicity=="1") if demo_ethnicity!=""
			la var ethnicity_white "Endline 1: White"
			
		gen ethnicity_black = (demo_ethnicity=="2") if demo_ethnicity!=""
			la var ethnicity_black "Endline 1: Black"

		gen ethnicity_hispanic = (demo_ethnicity=="3") if demo_ethnicity!=""
			la var ethnicity_hispanic "Endline 1: Hispanic/Latino"

		gen ethnicity_asian = (demo_ethnicity=="5") if demo_ethnicity!=""
			la var ethnicity_asian "Endline 1: Asian"
			
	* Generate wave indicator
	
		gen wave = 1
			
	* Redefine attriters as respondents who didn't complete any of the survey
	
		replace attrition_endline1 = 1 if progress==0

	* Redefine attriters as respondents for whom we don't have an affective polarization score
	
		replace attrition_endline1 = 1 if aff_pol_idx_noneg==.
	
		gen non_attrition_endline1 = 1-attrition_endline1
	
	
	
* Save
	
	save "Data/Cleaned/endline_1_merged.dta", replace
	
	

	
	
* Save version of dataset for wide panel

	preserve 
	
	foreach x of varlist _all {
		ren `x' r1_`x'
	}
	
	*ren r1_email_merged email_merged
	
	*sort email_merged
	
	save "Data/Cleaned/endline_1_merged_panel.dta", replace
	
	restore


